<?php
//include ('pe['host_root']/hook/wxlogin.hook.php');

$_SESSION['user_id'] = 64;
$_SESSION['user_vipcard_number'] = "40106335";
//$_SESSION['user_moneycard_number'] = "152879189497437";
$_SESSION['user_wxid'] = "o6PzEwtCkKHRMYC91O-5Ob5Yk7h4";
//exit;
//mp($_SESSION);

$_SESSION['page'] = "index";
if (!isset($_SESSION['user_id'])) {
    pe_goto('hotel.php?mod=login&act=wx_login&page=index');
}
switch ($act) {

    //#####################@ 修改分类 @#####################//
    case 'expect':

        include(pe_tpl('test.html'));
        break;

    case 'update_housestate':
        //传入住店离店日期


        //房间信息开始
        $fj_info = $db->pe_selectall('house');

        //房型房间数
        $sql = 'select ho.house_id,ho.house_name,ho.house_area,ho.house_rule,ho.house_server,ho.house_wxprice,ho.house_storeprice,ho.house_notice,ho.house_img,group_concat(fj.fj_number) as fj_number,count(ho.house_id) as nums from wxgg_house as ho join wxgg_fj as fj on ho.house_id = fj.fj_houseid   group by ho.house_id ';
        $house_info = $db->sql_selectall($sql);

        //房型房间订单数
        $sql2 = 'select ho.house_id,ho.house_name,group_concat(ord.order_number) as ord_number,count(ho.house_id)  as nums from wxgg_house as ho join wxgg_order as ord on ho.house_id = ord.order_houseid  where ord.order_startdate >= ' . $today_start_time . ' and ord.order_startdate <= ' . $today_end_time . ' group by ho.house_id ';
        $ord_info = $db->sql_selectall($sql2);


        //识别是否可以预定
        foreach ($fj_info as $k => $v) {
            $fj_info[$k]['houseimg'] = explode(',', $houseimg_info[$k]['houseimg']);
            $fj_info[$k]['img_num'] = $houseimg_info[$k]['img_num'];
            if ($v['nums'] < $ord_info[$k]['nums']) {
                $fj_info[$k]['can_order'] = 0;

            } else {
                $fj_info[$k]['can_order'] = 1;
            }
        }

        break;


    case 'hotelimg':
        $sql = 'select ho.hotelimg_id,ho.hotelimg_img,ho.hotelimg_category_id,ho.hotelimg_order,ho.hotelimg_state,hc.category_name,group_concat(ho.hotelimg_img) as hotelimg,group_concat(ho.hotelimg_order) as hotelorder from wxgg_hotelimg as ho join wxgg_hotelimgcate as hc where ho.hotelimg_category_id = hc.category_id group by ho.hotelimg_category_id';

        $hotelimg = $db->sql_selectall($sql);
        foreach ($hotelimg as $k => $v) {
            $hotelimg[$k]['hotelimg'] = explode(',', $v['hotelimg']);
            $hotelimg[$k]['hotelorder'] = explode(',', $v['hotelorder']);
            $hotelimg[$k]['hotelimg_num'] = count($hotelimg[$k]['hotelimg']);

        }
//        mp($hotelimg);exit;

        include(pe_tpl('hotelimg.html'));

        break;

    case 'del':

        include(pe_tpl('house_list.html'));
        break;

    case 'add':

        if (isGet()) {


        } else if (isPost()) {


        }

        break;

    case 'img_ajax':
        if (isGet()) {
            //房型图片
            $house_sql = 'select ho.house_name,ho.house_area,ho.house_rule,ho.house_server,ho.house_wxprice,ho.house_storeprice,ho.house_notice,ho.house_img,hi.houseimg_img,hi.houseimg_order,count(hi.houseimg_img) as img_num,group_concat(hi.houseimg_img) as houseimg,group_concat(hi.houseimg_order) as all_order  from wxgg_house as ho join wxgg_houseimg as hi on ho.house_id = hi.houseimg_houseid where hi.houseimg_state != 0 and ho.house_id = ' . $_g_house_id . ' group by ho.house_id order by hi.houseimg_order desc';
            $houseimg_info = $db->sql_select($house_sql);
            $houseimg_info['houseimg'] = explode(',', $houseimg_info['houseimg']);
            ob_clean();
            echo json_encode($houseimg_info);
        } else if (isPost()) {

        }

        break;


    case 'hotelimg_ajax':

        if (isGet()) {
            //房型图片
            if ($_g_category_id == 0) {
                $categoryimg = $db->pe_selectall('hotelimg');
            } else {
                $categoryimg = $db->pe_selectall('hotelimg', array('hotelimg_category_id' => $_g_category_id));
            }


            echo json_encode($categoryimg);

        }

        break;


    case 'daohang':

        $_g_address = "客天下万象国际公寓";
        include(pe_tpl('daohang.html'));
        break;


    //#####################@ 分类列表 @#####################//
//    default :
//        //默认当天时间
//        $today_start_time = strtotime(date('Y-m-d', time()) . ' 00:00:00');  //当天开始时间
//        $today_end_time = strtotime(date("Y-m-d") . ' 24:00:00'); //当天结束时间
//        //首页酒店顶部图片
//        $head_hotelimg = $db->pe_select('hotelimg', array('hotelimg_category_id' => 1));
//        //酒店措施
//        $hotel_server = $db->pe_selectall('server', '', '*', array(4));
//        //酒店图片总数
//        $img_num = count($db->pe_selectall('hotelimg'));
//        //酒店信息
//
//
//
//
//        $setting = $db->index('setting_key')->pe_selectall('setting');
//        $setting['web_near_station']['setting_value'] = explode('|', $setting['web_near_station']['setting_value']);
//        $setting['web_airport']['setting_value'] = explode('|', $setting['web_airport']['setting_value']);
//        $setting['web_near_interest']['setting_value'] = explode('|', $setting['web_near_interest']['setting_value']);
//
//        //房间信息开始
//        $fj_info = $db->pe_selectall('house');
//
//        //房型房间数
//        $sql = 'select ho.house_id,ho.house_name,ho.house_area,ho.house_rule,ho.house_server,ho.house_wxprice,ho.house_storeprice,ho.house_notice,ho.house_img,group_concat(fj.fj_number) as fj_number,count(ho.house_id) as nums from wxgg_house as ho join wxgg_fj as fj on ho.house_id = fj.fj_houseid where ho.house_state !=1   group by ho.house_id ';
//        $house_info = $db->sql_selectall($sql);
//
//        //房型房间订单数
//        $sql2 = 'select ho.house_id,ho.house_name,group_concat(ord.order_number) as ord_number,count(ho.house_id)  as nums from wxgg_house as ho join wxgg_order as ord on ho.house_id = ord.order_houseid  where ord.order_startdate >= ' . $today_start_time . ' and ord.order_startdate <= ' . $today_end_time . ' and ho.house_state !=1 group by ho.house_id ';
//        $ord_info = $db->sql_selectall($sql2);
//
//        //房型图片
//        $house_sql = 'select ho.house_name,ho.house_area,ho.house_rule,ho.house_server,ho.house_wxprice,ho.house_storeprice,ho.house_notice,ho.house_img,hi.houseimg_img,hi.houseimg_order,count(hi.houseimg_img) as img_num,group_concat(hi.houseimg_img) as houseimg,group_concat(hi.houseimg_order) as all_order  from wxgg_house as ho join wxgg_houseimg as hi on ho.house_id = hi.houseimg_houseid where hi.houseimg_state != 0 and ho.house_state !=1 group by ho.house_id order by hi.houseimg_order desc';
//        $houseimg_info = $db->sql_selectall($house_sql);
//
//        //识别是否可以预定
//        foreach ($fj_info as $k => $v) {
//            $fj_info[$k]['houseimg'] = explode(',', $houseimg_info[$k]['houseimg']);
//            $fj_info[$k]['img_num'] = $houseimg_info[$k]['img_num'];
//            if ($v['nums'] < $ord_info[$k]['nums']) {
//                $fj_info[$k]['can_order'] = 0;
//
//            } else {
//                $fj_info[$k]['can_order'] = 1;
//            }
//        }
////        mp($houseimg_info);exit;
//
//        include(pe_tpl('index.html'));


    //#####################@ 修改需求后的查询 @#####################//
    default :
//        mp($_SESSION);
        //默认当天时间
        $today_start_time = strtotime(date('Y-m-d', time()) . ' 00:00:00');  //当天开始时间
        $today_end_time = strtotime(date("Y-m-d") . ' 24:00:00'); //当天结束时间
        //首页酒店顶部图片
        $head_hotelimg = $db->pe_select('hotelimg', array('hotelimg_category_id' => 1));
        //酒店措施
        $ser_sql = 'select * from wxgg_server where server_state!=1 ';
        $hotel_server = $db->sql_selectall($ser_sql);
        //酒店图片总数
        $img_num = count($db->pe_selectall('hotelimg'));
        //酒店信息
        $setting = $db->index('setting_key')->pe_selectall('setting');
        $setting['web_near_station']['setting_value'] = explode('|', $setting['web_near_station']['setting_value']);
        $setting['web_airport']['setting_value'] = explode('|', $setting['web_airport']['setting_value']);
        $setting['web_near_interest']['setting_value'] = explode('|', $setting['web_near_interest']['setting_value']);

        //房型图片
        $house_sql = 'select ho.house_state,ho.house_id,ho.house_breakfast,ho.house_name,ho.house_area,ho.house_rule,ho.house_server,ho.house_wxprice,ho.house_storeprice,ho.house_notice,ho.house_img,hi.houseimg_img,hi.houseimg_order,count(hi.houseimg_img) as img_num,group_concat(hi.houseimg_img) as houseimg,group_concat(hi.houseimg_order) as all_order  from wxgg_house as ho join wxgg_houseimg as hi on ho.house_id = hi.houseimg_houseid where hi.houseimg_state != 0  group by ho.house_id order by hi.houseimg_order desc';

        $houseimg_info = $db->sql_selectall($house_sql);
        include(pe_tpl('index.html'));


}
